
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Tables"
clear
log using Table9.txt, text replace

***Q-sensitivity
clear
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data"
use LPSU_MainSample_Sep2024, replace
set matsize 10000
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Tables"

***Set of fixed effects
egen sic1year=group(sic1 year)
qui tabulate sic1year, generate(dsic1year)
egen month_post= group(month post)
qui tabulate month_post, generate(dmonth)
qui tabulate year_around_ipo, generate(deventyear) 


***Setting the sample to the IV sample (dropping observations colinear with FEs)

set more off
qui xtivreg2 log_assets_w log_medSqw (IPO IPO_Sq=instrument instrument_Sq) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
gen sample_ass=e(sample)
gen aux_ass=year
replace aux_ass=. if sample_ass==0
bysort id: egen count=count(aux_ass)
replace sample_ass=0 if count<2
drop count aux_ass

set matsize 10000
set more off
qui xtivreg2 log_sic3 log_medSqw (IPO IPO_Sq=instrument instrument_Sq) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* , fe first cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
gen sample_ind=e(sample)
gen aux_ind=year
replace aux_ind=. if sample_ind==0
bysort id: egen count=count(aux_ind)
replace sample_ind=0 if count<2
drop count aux_ind



***Sensitivity to Tobun's q

***Assets
**OLS
set more off
eststo:qui xtreg log_assets_w log_medSqw IPO IPO_Sq ///
 deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_ass==1, fe cluster(id) 
outreg2 using Table_Q_1.xls, keep(IPO IPO_Sq) sortvar(IPO IPO_Sq log_medSqw_res IPO_Sq_res) tex(frag) excel bdec(3) nocons nor2  label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, OLS, Instrument,-)  replace
**IV
set more off
eststo:qui xtivreg2 log_assets_w log_medSqw (IPO IPO_Sq=instrument instrument_Sq) ///
 deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_ass==1, fe nofirst cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_Q_1.xls, keep(IPO IPO_Sq) sortvar(IPO IPO_Sq log_medSqw_res IPO_Sq_res) tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes,Regression, Second stage,Instrument,Pre-IPO ret>0)  

***Industries
**OLS
set more off
eststo:qui xtreg log_sic3 log_medSqw IPO IPO_Sq ///
 deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_ind==1, fe cluster(id)
outreg2 using Table_Q_1.xls, keep(IPO IPO_Sq) sortvar(IPO IPO_Sq log_medSqw_res IPO_Sq_res) tex(frag) excel bdec(3) nocons nor2  label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Regression, OLS, Instrument,-)
 
**IV
set more off
eststo:qui xtivreg2 log_sic3 log_medSqw (IPO IPO_Sq=instrument instrument_Sq) ///
 deventyear2 deventyear3 deventyear4 deventyear5  dsic1year* dmonth* if sample_ind==1, fe nofirst cluster(id) partial(deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
outreg2 using Table_Q_1.xls, keep(IPO IPO_Sq) sortvar(IPO IPO_Sq log_medSqw_res IPO_Sq_res) tex(frag) excel bdec(3) nocons nor2 label ///
 addtext(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes,  IPO month x Post FE, Yes,Regression, Second stage,Instrument,Pre-IPO ret>0) 
 
esttab,   keep(IPO IPO_Sq) order(IPO IPO_Sq) ///
 label se b(%9.3f) se(%9.3f) nor2 star(* 0.1 ** 0.05 *** 0.01) addnotes(Firm FE, Yes, Event year FE, Yes, SIC x calendar year FE, Yes, IPO month x Post FE, Yes, Cols 1 & 3: OLS; Cols 2 & 4 IV) 
 
eststo clear   
 
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Tables"
log close 
